/*
 * @Description: 图表插件集成
 * @Date: 2021-09-13 15:06:05
 * @Author: 张自文
 * @LastEditTime: 2021-09-13 17:46:19
 * @LastEditors: 张自文
 * @FilePath: \flutter_demo_list\lib\pages\chart\chart_index.dart
 */
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ChartIndexPage extends StatelessWidget {
  ChartIndexPage({Key? key}) : super(key: key);
  final ChartIndexPageController vm = Get.put(ChartIndexPageController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: MyLineChart(),
      ),
    );
  }
}

class MyLineChart extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 第一条线
    List<FlSpot> spots1 = [
      FlSpot(1, 1),
      FlSpot(3, 1.5),
      FlSpot(5, 1.4),
      FlSpot(7, 3.4),
      FlSpot(9, 2),
      FlSpot(11, 2.2),
      FlSpot(13, 1.8),
    ];
    // 第二条线
    List<FlSpot> spots2 = [
      FlSpot(2, 1),
      FlSpot(4, 1.5),
      FlSpot(6, 1.4),
      FlSpot(8, 3),
      FlSpot(10, 1.6),
      FlSpot(12, 2.2),
    ];
    List<Linesales> dataLine = [
      new Linesales(new DateTime(2019, 7, 2), 33),
      new Linesales(new DateTime(2019, 7, 3), 55),
      new Linesales(new DateTime(2019, 7, 4), 22),
      new Linesales(new DateTime(2019, 7, 5), 88),
      new Linesales(new DateTime(2019, 7, 6), 123),
      new Linesales(new DateTime(2019, 7, 7), 75),
    ];

    return Container(
      height: 400.w,
      child: LineChart(
        LineChartData(
          lineBarsData: [
            LineChartBarData(
              spots: spots1,
            ),
            LineChartBarData(
              spots: spots2,
            ),
          ],
        ),
      ),
    );
  }
}

class Linesales {
  DateTime time;
  int sale;
  Linesales(this.time, this.sale);
}

class ChartIndexPageController extends GetxController {}
